#include "mainwindow.h"
#include "visitorlist.h"
#include <QLabel>
#include <QVBoxLayout>
#include <QPushButton>
#include <QTextEdit>

VisitorList::VisitorList(QWidget *parent)
    : QDialog{parent}
{
    setWindowTitle("访客单信息");
    QVBoxLayout *layout = new QVBoxLayout(this);

    // 输入访客信息
    layout->addWidget(new QLabel("访客姓名:"));
    nameInput = new QLineEdit("CC", this);
    layout->addWidget(nameInput);

    layout->addWidget(new QLabel("具体事由:"));
    eventInput = new QLineEdit("nothing", this);
    layout->addWidget(eventInput);

    layout->addWidget(new QLabel("公司:"));
    companyInput = new QLineEdit("XXX Software Technology Co., Ltd" , this);
    layout->addWidget(companyInput);

    layout->addWidget(new QLabel("访问日期:"));
    visitDateInput = new QLineEdit("2024/10/17", this);
    layout->addWidget(visitDateInput);

    layout->addWidget(new QLabel("联系方式"));
    visitPhone = new QLineEdit("16666666666", this);
    layout->addWidget(visitPhone);

    // 生成按钮
    QPushButton *generateButton = new QPushButton("生成访客单", this);
    layout->addWidget(generateButton);
    connect(generateButton, &QPushButton::clicked, this, &VisitorList::generateVisitorPass);

    // 输出区域
    outputArea = new QTextEdit(this);
    outputArea->setReadOnly(true);
    layout->addWidget(outputArea);

}

VisitorList::~VisitorList() {
}

void VisitorList::generateVisitorPass() {
    QString name = nameInput->text();
    QString event = eventInput->text();
    QString company = companyInput->text();
    QString visitDate = visitDateInput->text();
    QString phone = visitPhone->text();

    QString visitorPass = QString("访客单\n\n姓名: %1\n具体事由: %2\n公司: %3\n访问日期: %4\n联系方式: %5\n")
                              .arg(name)
                              .arg(event)
                              .arg(company)
                              .arg(visitDate)
                              .arg(phone);

    outputArea->setPlainText(visitorPass);

    MainWindow::getInstance().setTextEdit(visitorPass);
}
